package controller;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import main.Log;
import model.entity.Entity;
import model.skill.ActivateableSkill;
import view.ListProvider;
import view.View;

public class SkillsController extends Controller {
	private ListProvider skillListProvider;
	private Entity entity;
	/**
	 * The constructor that creates the instance of the SkillsController used with the Skill in MODEL and VIEW 
	 * @param entity
	 * @param skillListProvider
	 */
	public SkillsController(Entity entity, ListProvider skillListProvider) {
		this.setEntity(entity);
		this.skillListProvider = skillListProvider;
		this.skillListProvider.register(this);
		update(skillListProvider);
	}

	@Override
	public void update(View v) {
		List<ActivateableSkill> activateableSkill = getEntity().getOccupation().getCurrentActivateableSkills();
		//TODO HACK fix the arrow image loading
		//GameButton LEFT_CLICK = new GameButton("<", new Rectangle(upperLeftX-xOff, upperLeftY, iconWidth, iconHeight), ModelToImage.getImage("ArrowLeft"));
			for(ActivateableSkill as : activateableSkill) {//ActivateableSkillList) {
				final ActivateableSkill tempSkill = as;
				skillListProvider.getListenersMap().put(as, new MouseListener() {

				@Override
				public void mouseClicked(MouseEvent e) {
					Log.out(Log.CONTROLLER, "You clicked on " + tempSkill.getName());
					tempSkill.activate(entity);
				}
				@Override
				public void mouseEntered(MouseEvent e) {
					// TODO Auto-generated method stub
					
				}

				@Override
				public void mouseExited(MouseEvent e) {
					// TODO Auto-generated method stub
					
				}

				@Override
				public void mousePressed(MouseEvent e) {
					// TODO Auto-generated method stub
					
				}

				@Override
				public void mouseReleased(MouseEvent e) {
					// TODO Auto-generated method stub
				}
			});
		}
	}

	/**
	 * @param skillListProvider the skillListProvider to set
	 */
	public void setskillListProvider(ListProvider skillListProvider) {
		this.skillListProvider = skillListProvider;
	}

	/**
	 * @return the skillListProvider
	 */
	public ListProvider getskillListProvider() {
		return skillListProvider;
	}

	/**
	 * @param entity the entity to set
	 */
	public void setEntity(Entity entity) {
		this.entity = entity;
	}

	/**
	 * @return the entity
	 */
	public Entity getEntity() {
		return entity;
	}
	
}
